package demo.springboot.Controller;

import demo.springboot.POJO.T_product;
import demo.springboot.service.T_productService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping(value = "/product")
public class Product {
    @Autowired
    T_productService t_productService;


    @GetMapping(value = "")
    public String getBookList(ModelMap map, Model model) {
        return "redirect:product/police-box";
    }


    @GetMapping(value = "/{type}")
    public String product(ModelMap map, Model model ,     @PathVariable String type    ) {
        List<T_product> t_products = t_productService.findByType(type);
        model.addAttribute("pageinfo" , t_products);
//        return "/product/category.html";
        return "product/index.html";
    }



    @GetMapping(value = "/id/{id}")
    public String product_detail(ModelMap map, Model model ,     @PathVariable Integer id    ) {
        T_product t_products = t_productService.findById(id);
        model.addAttribute("pageinfo" , t_products);
//        return "/product/category.html";
        return "product/product_details.html";
    }







}
